Migrate avoid unrelated type assertions and its tests#239
Migrate avoid unrelated type assertions and its tests#239daria-trusca-solid wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request migrates the avoid_unrelated_type_assertions lint rule from custom_lint_builder to the standard analyzer package's AnalysisRule framework, updating the rule registration, refactoring the visitor to report diagnostics directly, and adding comprehensive unit tests. The feedback suggests changing the visitor's base class from RecursiveAstVisitor to SimpleAstVisitor to avoid redundant AST traversals since the visitor is already registered specifically for IsExpression nodes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| /// AST Visitor which finds all is expressions and checks if they are | ||
| /// unrelated (result always false) | ||
| /// Visitor for [AvoidUnrelatedTypeAssertionsRule]. | ||
| class AvoidUnrelatedTypeAssertionsVisitor extends RecursiveAstVisitor<void> { |
There was a problem hiding this comment.
Since this visitor is registered specifically for IsExpression nodes via registry.addIsExpression, the analyzer engine will automatically traverse the AST and dispatch all IsExpression nodes to this visitor.\n\nUsing RecursiveAstVisitor causes the visitor to recursively traverse the AST children of each IsExpression node again. This leads to redundant traversals and can cause nested IsExpression nodes to be visited and reported multiple times.\n\nChanging the base class to SimpleAstVisitor avoids this redundant traversal and ensures each node is processed exactly once.
| class AvoidUnrelatedTypeAssertionsVisitor extends RecursiveAstVisitor<void> { | |
| class AvoidUnrelatedTypeAssertionsVisitor extends SimpleAstVisitor<void> { |
Migrated the
avoid_unrelated_type_assertionsrule and its corresponding tests to comply with theanalyzerpackage.Changes
avoid_unrelated_type_assertionsto use the current analyzer syntax.